package com.example.myapplication.viewModel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.example.myapplication.common.Res;

import cn.hutool.core.util.StrUtil;

public class LoginViewModel extends ViewModel {


    public MutableLiveData<Boolean> isLogin = new MutableLiveData<>();
    public MutableLiveData<String> username = new MutableLiveData<>();

    public MutableLiveData<String> password = new MutableLiveData<>();

    public void login(String username, String password, MutableLiveData<Res> resMutableLiveData) {
        new Thread() {
            @Override
            public void run() {
                super.run();
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {
                    if (StrUtil.equals(username, "admin") && StrUtil.equals(password, "123456")) {
                        resMutableLiveData.postValue(Res.ok());
                    } else {
                        resMutableLiveData.postValue(Res.fail());
                    }
                }
            }
        }.start();
    }
}
